using System.Linq;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Records;

namespace LazyFieldDemo.Models {
    public class AddressPart : ContentPart<AddressPartRecord>, ITitleAspect {

        public string AddressLine1 {
            get { return Record.AddressLine1; }
            set { Record.AddressLine1 = value; }
        }

        public string AddressLine2 {
            get { return Record.AddressLine2; }
            set { Record.AddressLine2 = value; }
        }

        public string Zipcode {
            get { return Record.Zipcode; }
            set { Record.Zipcode = value; }
        }

        public string City {
            get { return Record.City; }
            set { Record.City = value; }
        }

        public Country Country {
            get { return Record.Country; }
            set { Record.Country = value; }
        }

        public string Title {
            get { return string.Join(", ", new[]{AddressLine1, AddressLine2, Zipcode, City, Country != null ? Country.Name : ""}.Where(x => !string.IsNullOrWhiteSpace(x))); }
        }
    }

    public class AddressPartRecord : ContentPartRecord {
        public virtual string AddressLine1 { get; set; }
        public virtual string AddressLine2 { get; set; }
        public virtual string Zipcode { get; set; }
        public virtual string City { get; set; }
        public virtual Country Country { get; set; }
    }
}